#include "component/piximage.h"

/********************************************
 *              Public
 ********************************************/

    /********************************************
     *              Constructors
     ********************************************/

        PixImage::PixImage(){
        }

        PixImage::PixImage(xml::Element &element){
            Load(element);
            m_Item      =   new ComponentItem(Name(), this);
        }

        PixImage::PixImage(QString path, QString filename){
            m_Path      =   path;
            Name(filename.toStdString());
            m_Item      =   new ComponentItem(filename.toStdString(), this);
        }

    /********************************************
     *              Methods
     ********************************************/

        /********************************************
         *              Get
         ********************************************/

             QString  PixImage::Path() const{
                return m_Path;
            }

        /********************************************
         *              Set
         ********************************************/

        /********************************************
         *              Virtual
         ********************************************/

            void PixImage::Save( xml::Element & element ){
                xml::Element * pixImage =   new xml::Element("PixImage");

                xml::Element * path     =   new xml::Element("Path");
                xml::Element * name     =   new xml::Element("Name");

                xml::Element * width    =   new xml::Element("Width");
                xml::Element * height   =   new xml::Element("Height");

                element.AppendChild(*pixImage);

                pixImage->AppendChild(*path);
                pixImage->AppendChild(*name);
                pixImage->AppendChild(*width);
                pixImage->AppendChild(*height);

                width->AppendText("100");
                height->AppendText("100");

                path->AppendText(Path().toStdString());
                name->AppendText(Name());
            }

            void PixImage::Load(class xml::Element & element){

                Name(element.GetElementByTagName("Name")->Value());
                m_Path  =  QString::fromStdString(element.GetElementByTagName("Path")->Value());

                string path = Path().toStdString();

                char chars[]="\t\n";

                for (unsigned int i = 0; i < strlen(chars); ++i)
                {
                   // you need include <algorithm> to use general algorithms like std::remove()
                    m_Name.erase (std::remove(m_Name.begin(), m_Name.end(), chars[i]), m_Name.end());
                    path.erase (std::remove(path.begin(), path.end(), chars[i]), path.end());
                }
                m_Path= QString::fromStdString(path);


            }



